package com.epfresh.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.epfresh.R;
import com.epfresh.global.BaseActivity;

public class OrderSuccessActivity extends BaseActivity {

    static final String TAG = "OrderSuccessActivity";
    TextView sure;
    private TextView tvFactSum,tvWallet,tvNoPay,tvOnLinePay;
    private LinearLayout llFee;
    String factSum,wallets,noPay,onLinePay;
    /*
    * 从上至下 最多4个   分两种情况：购物车过来，无需支付，直接屏蔽以下四个；   除此之外 总额 = 已使用钱包余额 + 在线支付 非0则显示
    * 总额
    * 已使用钱包余额
    * 在线支付
    * 未支付
    * */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (savedInstanceState != null) {
            getIntent().putExtra("factSum", savedInstanceState.getString("factSum"));
            getIntent().putExtra("wallets", savedInstanceState.getString("wallets"));
            getIntent().putExtra("noPay", savedInstanceState.getString("noPay"));
            getIntent().putExtra("onLinePay", savedInstanceState.getString("onLinePay"));
        }

        initView();
        baseback.setVisibility(View.VISIBLE);
        basetitle.setText("下单成功");
        initMoneyNumber();
    }
    void initView(){
        setContentView(R.layout.activity_ordersuccess);
        sure = (TextView)findViewById(R.id.sure);
        tvFactSum = (TextView)findViewById(R.id.tv_fact_sum);
        llFee = (LinearLayout)findViewById(R.id.ll_fee);
        sure.setOnClickListener(this);
        tvWallet = (TextView)findViewById(R.id.tv_wallet);
        tvNoPay = (TextView)findViewById(R.id.tv_no_pay);
        tvOnLinePay = (TextView)findViewById(R.id.tv_online);
    }


    @Override
    protected void onSaveInstanceState(Bundle outState) {
        outState.putString("factSum", factSum);
        outState.putString("wallets", wallets);
        outState.putString("noPay", noPay);
        outState.putString("onLinePay", onLinePay);
        super.onSaveInstanceState(outState);
    }


    void initMoneyNumber(){
        if(getIntent().getBooleanExtra("noNeedPay",false)==true){//一般为货到付款，无需显示钱数
            llFee.setVisibility(View.GONE);
            return;
        }/*
                            success.putExtra("factSum", detail.getPayAllMoney());
                    success.putExtra("wallets", date.getPayWallets());
                    success.putExtra("noPay",date.getUnPayValue());
                    success.putExtra("onLinePay",date.getPayOnlineValue());
        */
        factSum = getIntent().getStringExtra("factSum");
        wallets = getIntent().getStringExtra("wallets");
        noPay = getIntent().getStringExtra("noPay");
        onLinePay = getIntent().getStringExtra("onLinePay");
        if(factSum==null||factSum.equals("")||factSum.equals("null")){
            tvFactSum.setVisibility(View.GONE);
        }else {
            tvFactSum.setText(factSum + "元");
            tvFactSum.setVisibility(View.VISIBLE);
        }
        if(wallets==null||wallets.equals("")||wallets.equals("null")||wallets.equals("0.00")){
            tvWallet.setVisibility(View.GONE);
        }else {
            tvWallet.setText(tvWallet.getText().toString()+wallets+"元");
            tvWallet.setVisibility(View.VISIBLE);
        }
        if(noPay==null||noPay.equals("")||noPay.equals("null")||noPay.equals("0.00")){
            tvNoPay.setVisibility(View.GONE);
        }else {
            tvNoPay.setVisibility(View.VISIBLE);
            tvNoPay.setText(tvNoPay.getText().toString()+noPay+"元");
        }
        if(onLinePay==null||onLinePay.equals("")||onLinePay.equals("null")||onLinePay.equals("0.00")){
            tvOnLinePay.setVisibility(View.GONE);
        }else {
            tvOnLinePay.setVisibility(View.VISIBLE);
            tvOnLinePay.setText(tvOnLinePay.getText().toString()+onLinePay+"元");
        }
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.baseback:
                Intent intent = new Intent(OrderSuccessActivity.this,HomeActivity.class);
                intent.putExtra("refreshFlag","refreshHomeCart");
                startActivity(intent);
                finish();
                break;
            case R.id.sure:
                Intent detail = new Intent(this,MyOrderActivity.class);
                detail.putExtra("homeFlag",true);
                startActivity(detail);
                finish();
                break;
        }
    }

    @Override
    public void onBackPressed() {
        finish();
    }


}
